package com.alfayun.fiscalriskanalysis.another.indicator;

import java.io.IOException;
import java.math.BigDecimal;

import com.alfayun.fiscalriskanalysis.another.specification.indicator.MeasureSpec;
import com.fasterxml.jackson.databind.ObjectMapper;

public final class Measures {

	private static ObjectMapper mapper = new ObjectMapper();

	public static Measure create(MeasureSpec spec) throws IOException {
		switch (spec.type) {
		case CONST:
			return new ConstMeasure(spec.id, spec.code, spec.name, new BigDecimal(spec.script));

		case CELL_VALUE:
			/** script: { "selector": "<selector id>", "rowNum": int, "columnNum": int } */
			var node = mapper.readTree(spec.script);

			return new CellValueMeasure(spec, node.at("/selector").textValue(), node.at("/rowNum").intValue(), node.at("/columnNum").intValue());

		case JAVA_FUNCTION:
			break;
		case SCRIPT:
			break;
		default:
			break;
		}

		return null;
	}

	private Measures() {
		// Empty.
	}
}
